
<html>
<title>font - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>


<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
<tr>
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
	||&nbsp;
	<a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||
	<a href=index.html>Reference Index</a> &nbsp;||
	<br>&nbsp;<br>
	
<a href=cdrom.html>Cdrom</a>&nbsp;||&nbsp;
<a href=cursors.html>Cursors</a>&nbsp;||&nbsp;
<a href=display.html>Display</a>&nbsp;||&nbsp;
<a href=draw.html>Draw</a>&nbsp;||&nbsp;
<a href=event.html>Event</a>&nbsp;||&nbsp;
<a href=font.html>Font</a>&nbsp;||&nbsp;
<a href=image.html>Image</a>&nbsp;||&nbsp;
<a href=joystick.html>Joystick</a>&nbsp;||&nbsp;
<a href=key.html>Key</a>&nbsp;||&nbsp;
<a href=mixer.html>Mixer</a>&nbsp;||&nbsp;
<a href=mouse.html>Mouse</a>&nbsp;||&nbsp;
<a href=movie.html>Movie</a>&nbsp;||&nbsp;
<a href=music.html>Music</a>&nbsp;||&nbsp;
<a href=overlay.html>Overlay</a>&nbsp;||&nbsp;
<a href=pygame.html>Pygame</a>&nbsp;||&nbsp;
<a href=rect.html>Rect</a>&nbsp;||&nbsp;
<a href=scrap.html>Scrap</a>&nbsp;||&nbsp;
<a href=sndarray.html>Sndarray</a>&nbsp;||&nbsp;
<a href=sprite.html>Sprite</a>&nbsp;||&nbsp;
<a href=surface.html>Surface</a>&nbsp;||&nbsp;
<a href=surfarray.html>Surfarray</a>&nbsp;||&nbsp;
<a href=time.html>Time</a>&nbsp;||&nbsp;
<a href=transform.html>Transform</a>
</td></tr></table>
<br>


<a name="pygame.font">
<big><b>pygame.font</big></b><br><ul>
  <i>pygame module for loading and rendering fonts</i><br>
<ul><small><table>
  <tr><td><a href="font.html#pygame.font.init">pygame.font.init</a> - <font size=-1>initialize the font module</font></td><td>initialize the font module</td></tr>
  <tr><td><a href="font.html#pygame.font.quit">pygame.font.quit</a> - <font size=-1>uninitialize the font module</font></td><td>uninitialize the font module</td></tr>
  <tr><td><a href="font.html#pygame.font.get_init">pygame.font.get_init</a> - <font size=-1>true if the font module is initialized</font></td><td>true if the font module is initialized</td></tr>
  <tr><td><a href="font.html#pygame.font.get_default_font">pygame.font.get_default_font</a> - <font size=-1>get the filename of the default font</font></td><td>get the filename of the default font</td></tr>
  <tr><td><a href="font.html#pygame.font.get_fonts">pygame.font.get_fonts</a> - <font size=-1>get all available fonts</font></td><td>get all available fonts</td></tr>
  <tr><td><a href="font.html#pygame.font.match_font">pygame.font.match_font</a> - <font size=-1>find a specific font on the system</font></td><td>find a specific font on the system</td></tr>
  <tr><td><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></td><td>create a Font object from the system fonts</td></tr>
  <tr><td><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></td><td>create a new Font object from a file</td></tr>
</table></small></ul>
<p>The font module allows for rendering TrueType fonts into a new Surface object. This module is optional and requires SDL_ttf as a dependency. You should test that <tt>pygame.font</tt> is available and initialized before attempting to use the module. </p>
<p>Most of the work done with fonts are done by using the actual Font objects. The module by itself only has routines to initialize the module and create Font objects with <tt><a href="font.html#pygame.font.Font">pygame.font.Font</a> - <font size=-1>create a new Font object from a file</font></tt>. </p>
<p>You can load fonts from the system by using the <tt><a href="font.html#pygame.font.SysFont">pygame.font.SysFont</a> - <font size=-1>create a Font object from the system fonts</font></tt> function. There are a few other functions to help lookup the system fonts. </p>
<p>Pygame comes with a builtin default font. This can always be accessed by passing None as the font name. </p>
<!--COMMENTS:pygame.font--> &nbsp;<br> 


<a name="pygame.font.init">
<big><b>pygame.font.init</big></b><br><ul>
  <i>initialize the font module</i><br>
  <tt>pygame.font.init(): return None</tt><br>
<p>This method is called automatically by <tt><a href="pygame.html#pygame.init">pygame.init</a> - <font size=-1>initialize all imported pygame modules</font></tt>. It initializes the font module. The module must be initialized before any other functions will work. </p>
<p>It is safe to call this function more than once. </p>
<!--COMMENTS:pygame.font.init--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.quit">
<big><b>pygame.font.quit</big></b><br><ul>
  <i>uninitialize the font module</i><br>
  <tt>pygame.font.quit(): return None</tt><br>
<p>Manually uninitialize SDL_ttf's font system. This is called automatically by <tt><a href="pygame.html#pygame.quit">pygame.quit</a> - <font size=-1>uninitialize all pygame modules</font></tt>. </p>
<p>It is safe to call this function even if font is currently not initialized. </p>
<!--COMMENTS:pygame.font.quit--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.get_init">
<big><b>pygame.font.get_init</big></b><br><ul>
  <i>true if the font module is initialized</i><br>
  <tt>pygame.font.get_init(): return bool</tt><br>
<p>Test if the font module is initialized or not. </p>
<!--COMMENTS:pygame.font.get_init--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.get_default_font">
<big><b>pygame.font.get_default_font</big></b><br><ul>
  <i>get the filename of the default font</i><br>
  <tt>pygame.font.get_default_font(): return string</tt><br>
<p>Return the filename of the system font. This is not the full path to the file. This file can usually be found in the same directory as the font module, but it can also be bundled in separate archives. </p>
<!--COMMENTS:pygame.font.get_default_font--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.get_fonts">
<big><b>pygame.font.get_fonts</big></b><br><ul>
  <i>get all available fonts</i><br>
  <tt>pygame.font.get_fonts(): return list of strings</tt><br>
<p>Returns a list of all the fonts available on the system. The names of the fonts will be set to lowercase with all spaces and punctuation removed. This works on most systems, but some will return an empty list if they cannot find fonts. </p>
<!--COMMENTS:pygame.font.get_fonts--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.match_font">
<big><b>pygame.font.match_font</big></b><br><ul>
  <i>find a specific font on the system</i><br>
  <tt>pygame.font.match_font(name, bold=False, italic=False): return path</tt><br>
<p>Returns the full path to a font file on the system. If bold or italic are set to true, this will attempt to find the correct family of font. </p>
<p>The font name can actually be a comma separated list of font names to try. If none of the given names are found, None is returned. </p>
<p>Example: </p>
<pre>    print pygame.font.match_font('bitstreamverasans')
    # output is: /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf
    # (but only if you have Vera on your system)
</pre>
<!--COMMENTS:pygame.font.match_font--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.SysFont">
<big><b>pygame.font.SysFont</big></b><br><ul>
  <i>create a Font object from the system fonts</i><br>
  <tt>pygame.font.SysFont(name, size, bold=False, italic=False): return Font</tt><br>
<p>Return a new Font object that is loaded from the system fonts. The font will match the requested bold and italic flags. If a suitable system font is not found this will fallback on loading the default pygame font. The font name can be a comma separated list of font names to look for. </p>
<!--COMMENTS:pygame.font.SysFont--> &nbsp;<br> 
<br></ul>


<a name="pygame.font.Font">
<big><b>pygame.font.Font</big></b><br><ul>
  <i>create a new Font object from a file</i><br>
  <tt>pygame.font.Font(filename, size): return Font</tt><br>
  <tt>pygame.font.Font(object, size): return Font</tt><br>
<ul><small><table>
  <tr><td><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></td><td>draw text on a new Surface</td></tr>
  <tr><td><a href="font.html#Font.size">Font.size</a> - <font size=-1>determine the amount of space needed to render text</font></td><td>determine the amount of space needed to render text</td></tr>
  <tr><td><a href="font.html#Font.set_underline">Font.set_underline</a> - <font size=-1>control if text is rendered with an underline</font></td><td>control if text is rendered with an underline</td></tr>
  <tr><td><a href="font.html#Font.get_underline">Font.get_underline</a> - <font size=-1>check if text will be rendered with an underline</font></td><td>check if text will be rendered with an underline</td></tr>
  <tr><td><a href="font.html#Font.set_bold">Font.set_bold</a> - <font size=-1>enable fake rendering of bold text</font></td><td>enable fake rendering of bold text</td></tr>
  <tr><td><a href="font.html#Font.get_bold">Font.get_bold</a> - <font size=-1>check if text will be rendered bold</font></td><td>check if text will be rendered bold</td></tr>
  <tr><td><a href="font.html#Font.set_italic">Font.set_italic</a> - <font size=-1>enable fake rendering of italic text</font></td><td>enable fake rendering of italic text</td></tr>
  <tr><td><a href="font.html#Font.get_italic">Font.get_italic</a> - <font size=-1>check if the text will be rendered italic</font></td><td>check if the text will be rendered italic</td></tr>
  <tr><td><a href="font.html#Font.get_linesize">Font.get_linesize</a> - <font size=-1>get the line space of the font text</font></td><td>get the line space of the font text</td></tr>
  <tr><td><a href="font.html#Font.get_height">Font.get_height</a> - <font size=-1>get the height of the font</font></td><td>get the height of the font</td></tr>
  <tr><td><a href="font.html#Font.get_ascent">Font.get_ascent</a> - <font size=-1>get the ascent of the font</font></td><td>get the ascent of the font</td></tr>
  <tr><td><a href="font.html#Font.get_descent">Font.get_descent</a> - <font size=-1>get the descent of the font</font></td><td>get the descent of the font</td></tr>
</table></small></ul>
<p>Load a new font from a given filename or a python file object. The size is the height of the font in pixels. If the filename is None the Pygame default font will be loaded. If a font cannot be loaded from the arguments given an exception will be raised. Once the font is created the size cannot be changed. </p>
<p>Font objects are mainly used to render text into new Surface objects. The render can emulate bold or italic features, but it is better to load from a font with actual italic or bold glyphs. The rendered text can be regular strings or unicode. </p>
<!--COMMENTS:pygame.font.Font--> &nbsp;<br> 


<a name="Font.render">
<big><b>Font.render</big></b><br><ul>
  <i>draw text on a new Surface</i><br>
  <tt>Font.render(text, antialias, color, background=None): return Surface</tt><br>
<p>This creates a new Surface with the specified text rendered on it. Pygame provides no way to directly draw text on an existing Surface: instead you must use <tt><a href="font.html#Font.render">Font.render</a> - <font size=-1>draw text on a new Surface</font></tt> to create an image (Surface) of the text, then blit this image onto another Surface. </p>
<p>The text can only be a single line: newline characters are not rendered. The antialias argument is a boolean: if true the characters will have smooth edges. The color argument is the color of the text <tt>[e.g.:</tt> (0,0,255) for blue]. The optional background argument is a color to use for the text background. If no background is passed the area outside the text will be transparent. </p>
<p>The Surface returned will be of the dimensions required to hold the text. (the same as those returned by <tt>Font.size())</tt>. If an empty string is passed for the text, a blank surface will be returned that is one pixel wide and the height of the font. </p>
<p>Depending on the type of background and antialiasing used, this returns different types of Surfaces. For performance reasons, it is good to know what type of image will be used. If antialiasing is not used, the return image will always be an 8bit image with a two color palette. If the background is transparent a colorkey will be set. Antialiased images are rendered to 24-bit <tt>RGB</tt> images. If the background is transparent a pixel alpha will be included. </p>
<p>Optimization: if you know that the final destination for the text (on the screen) will always have a solid background, and the text is antialiased, you can improve performance by specifying the background color. This will cause the resulting image to maintain transparency information by colorkey rather than (much less efficient) alpha values. </p>
<p>If you render '\n' a unknown char will be rendered. Usually a rectangle. Instead you need to handle new lines yourself. </p>
<p>Font rendering is not thread safe: only a single thread can render text any time. </p>
<!--COMMENTS:Font.render--> &nbsp;<br> 
<br></ul>


<a name="Font.size">
<big><b>Font.size</big></b><br><ul>
  <i>determine the amount of space needed to render text</i><br>
  <tt>Font.size(text): return (width, height)</tt><br>
<p>Returns the dimensions needed to render the text. This can be used to help determine the positioning needed for text before it is rendered. It can also be used for wordwrapping and other layout effects. </p>
<p>Be aware that most fonts use kerning which adjusts the widths for specific letter pairs. For example, the width for "ae" will not always match the width for "a" + "e". </p>
<!--COMMENTS:Font.size--> &nbsp;<br> 
<br></ul>


<a name="Font.set_underline">
<big><b>Font.set_underline</big></b><br><ul>
  <i>control if text is rendered with an underline</i><br>
  <tt>Font.set_underline(bool): return None</tt><br>
<p>When enabled, all rendered fonts will include an underline. The underline is always one pixel thick, regardless of font size. This can be mixed with the bold and italic modes. </p>
<!--COMMENTS:Font.set_underline--> &nbsp;<br> 
<br></ul>


<a name="Font.get_underline">
<big><b>Font.get_underline</big></b><br><ul>
  <i>check if text will be rendered with an underline</i><br>
  <tt>Font.get_underline(): return bool</tt><br>
<p>Return True when the font underline is enabled. </p>
<!--COMMENTS:Font.get_underline--> &nbsp;<br> 
<br></ul>


<a name="Font.set_bold">
<big><b>Font.set_bold</big></b><br><ul>
  <i>enable fake rendering of bold text</i><br>
  <tt>Font.set_bold(bool): return None</tt><br>
<p>Enables the bold rendering of text. This is a fake stretching of the font that doesn't look good on many font types. If possible load the font from a real bold font file. While bold, the font will have a different width than when normal. This can be mixed with the italic and underline modes. </p>
<!--COMMENTS:Font.set_bold--> &nbsp;<br> 
<br></ul>


<a name="Font.get_bold">
<big><b>Font.get_bold</big></b><br><ul>
  <i>check if text will be rendered bold</i><br>
  <tt>Font.get_bold(): return bool</tt><br>
<p>Return True when the font bold rendering mode is enabled. </p>
<!--COMMENTS:Font.get_bold--> &nbsp;<br> 
<br></ul>


<a name="Font.set_italic">
<big><b>Font.set_italic</big></b><br><ul>
  <i>enable fake rendering of italic text</i><br>
  <tt>Font.set_bold(bool): return None</tt><br>
<p>Enables fake rendering of italic text. This is a fake skewing of the font that doesn't look good on many font types. If possible load the font from a real italic font file. While italic the font will have a different width than when normal. This can be mixed with the bold and underline modes. </p>
<!--COMMENTS:Font.set_italic--> &nbsp;<br> 
<br></ul>


<a name="Font.get_italic">
<big><b>Font.get_italic</big></b><br><ul>
  <i>check if the text will be rendered italic</i><br>
  <tt>Font.get_italic(): return bool</tt><br>
<p>Return True when the font italic rendering mode is enabled. </p>
<!--COMMENTS:Font.get_italic--> &nbsp;<br> 
<br></ul>


<a name="Font.get_linesize">
<big><b>Font.get_linesize</big></b><br><ul>
  <i>get the line space of the font text</i><br>
  <tt>Font.get_linesize(): return int</tt><br>
<p>Return the height in pixels for a line of text with the font. When rendering multiple lines of text this is the recommended amount of space between lines. </p>
<!--COMMENTS:Font.get_linesize--> &nbsp;<br> 
<br></ul>


<a name="Font.get_height">
<big><b>Font.get_height</big></b><br><ul>
  <i>get the height of the font</i><br>
  <tt>Font.get_height(): return int</tt><br>
<p>Return the height in pixels of the actual rendered text. This is the average size for each glyph in the font. </p>
<!--COMMENTS:Font.get_height--> &nbsp;<br> 
<br></ul>


<a name="Font.get_ascent">
<big><b>Font.get_ascent</big></b><br><ul>
  <i>get the ascent of the font</i><br>
  <tt>Font.get_ascent(): return int</tt><br>
<p>Return the height in pixels for the font ascent. The ascent is the number of pixels from the font baseline to the top of the font. </p>
<!--COMMENTS:Font.get_ascent--> &nbsp;<br> 
<br></ul>


<a name="Font.get_descent">
<big><b>Font.get_descent</big></b><br><ul>
  <i>get the descent of the font</i><br>
  <tt>Font.get_descent(): return int</tt><br>
<p>Return the height in pixels for the font descent. The descent is the number of pixels from the font baseline to the bottom of the font. </p>
<!--COMMENTS:Font.get_descent--> &nbsp;<br> 
<br></ul>
<br></ul>
<br></ul>

</body></html>
